package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.os.model.FoodS;
import com.os.service.FoodServiceS;
import com.os.serviceimpl.FoodServiceImplS;

import net.sf.json.JSONObject;

public class LoadFoodControllerS extends HttpServlet{
	FoodServiceS fs = new FoodServiceImplS();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("utf8");
		PrintWriter pw = resp.getWriter();
		int page = Integer.parseInt(req.getParameter("page"));
		int rows = Integer.parseInt(req.getParameter("rows"));
		int total = fs.FindFoodCountS();
		List<FoodS> foods= fs.FindFoodsS(page, rows);
		JSONObject  j = new JSONObject();
		j.put("total", total);
		j.put("rows", foods);
		pw.write(j.toString());
	}
}
